package ocean.chinacraft.client.screen.function;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import ocean.chinacraft.common.world.block.function.container.SericultureFrameBlockContainer;
import ocean.chinacraft.common.constants.Constants;

import javax.annotation.Nonnull;

/**
 * 养蚕架界面
 *
 * @author zhang
 * @since 2021/11/15
 */
public class SericultureFrameBlockScreen extends ContainerScreen<SericultureFrameBlockContainer> {

    private static final ResourceLocation GUI = new ResourceLocation(Constants.MOD_ID,
            "textures/gui/sericulture_frame_block.png");

    private static final ITextComponent NEED_LEAF = new TranslationTextComponent("container.sericulture.need_leaf");

    private static final ITextComponent NEED_RAIN_PROTECTION = new TranslationTextComponent("container.sericulture" +
            ".need_rain_protection");

    private static final ITextComponent SILKWORM_COCOONS_FULL = new TranslationTextComponent("container.sericulture" +
            ".silkworm_cocoons_full");


    public SericultureFrameBlockScreen(SericultureFrameBlockContainer screenContainer, PlayerInventory inv,
                                       ITextComponent titleIn) {
        super(screenContainer, inv, titleIn);
    }

    @Override
    public void render(@Nonnull MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        this.renderBackground(matrixStack);
        super.render(matrixStack, mouseX, mouseY, partialTicks);
        this.renderTooltip(matrixStack, mouseX, mouseY);
    }

    @Override
    protected void renderBg(MatrixStack matrixStack, float partialTicks, int x, int y) {
        RenderSystem.color4f(1f, 1f, 1f, 1f);
        this.minecraft.getTextureManager().bind(GUI);
        int i = this.leftPos;
        int j = this.topPos;

        int k = (this.width - this.getXSize()) / 2;
        int l = (this.height - this.getYSize()) / 2;

        int v = (int) (36 * (inventory.player.level.getGameTime() % 48) / 48.0F);

        this.blit(matrixStack, i, j, -1, -2, this.imageWidth, this.imageHeight);
        if (menu.allow() == 0 || menu.allow() == 1 || menu.allow() == 3) {
            this.blit(matrixStack, k + 122, l + 48, 176, 20, v, 30);
        } else {
            this.blit(matrixStack, k + 122, l + 47, 176, 0, 26, 20);
        }
    }

    @Override
    protected void renderLabels(MatrixStack matrixStack, int p_230451_2_, int p_230451_3_) {
        ITextComponent itextcomponent = null;

        if (menu.addInformation() == 1 || menu.addInformation() == 4) {
            itextcomponent = NEED_LEAF;
        } else if (menu.addInformation() == 2) {
            itextcomponent = NEED_RAIN_PROTECTION;
        } else if (menu.addInformation() == 3) {
            itextcomponent = SILKWORM_COCOONS_FULL;
        }
        if (itextcomponent != null) {
            this.font.drawShadow(matrixStack, itextcomponent, 40, 55, 16736352);
        }
    }
}
